package gui.panels;

import gui.tools.ActionHandler;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mysql.LocationQueries;
import mysql.MoviesQueries;
import objects.Location;
import objects.Movie;

public class MoviePanel extends JPanel {

	public Movie mcurrentEntry;
	public MoviesQueries mmovieQueries;
	public List<Movie> mResults;
	public int mnumberOfEntries = 0;
	public int mCurrentEntryIndex = 0;
	
	public LocationQueries locQueries;
	public List<Location> locResults;

	public JTextField moidText;
	private JLabel moidLabel;
	public JTextField titleText;
	private JLabel titleLabel;
	public JTextField yearText;
	private JLabel yearLabel;
	public JTextField lidText;
	private JLabel lidLabel;
	public JTextField outText;
	private JLabel outLabel;

	public JButton next;
	public JButton previous;
	public JPanel navigatePanel;
	public JTextField index;
	private JPanel displayPanel;
	public JButton add;
	
	public MoviePanel(ActionHandler ac) {
		getData();
		moidLabel = new JLabel("Movie ID:");
		moidText = new JTextField(2);
		titleLabel = new JLabel("Title:");
		titleText = new JTextField(10);
		yearLabel = new JLabel("Year:");
		yearText = new JTextField(10);
		lidLabel = new JLabel("Location ID:");
		lidText = new JTextField(10);
		outLabel = new JLabel("Is out:");
		outText = new JTextField(5);

		next = new JButton("Next");
		previous = new JButton("Previous");
		navigatePanel = new JPanel();
		index = new JTextField(2);
		displayPanel = new JPanel();
		add = new JButton("Add new movie");
		
		moidText.setEditable(false);
		titleText.setEditable(false);
		yearText.setEditable(false);
		lidText.setEditable(false);
		outText.setEditable(false);

		setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

		next.addActionListener(ac);
		previous.addActionListener(ac);
		navigatePanel.setLayout(new BoxLayout(navigatePanel, BoxLayout.X_AXIS));
		navigatePanel.add(previous);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(index);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(next);
		add(navigatePanel);

		displayPanel.setLayout(new GridLayout(5, 2, 4, 4));
		displayPanel.add(moidLabel);
		moidText.setEditable(false);
		displayPanel.add(moidText);
		displayPanel.add(titleLabel);
		displayPanel.add(titleText);
		displayPanel.add(yearLabel);
		displayPanel.add(yearText);
		displayPanel.add(lidLabel);
		displayPanel.add(lidText);
		displayPanel.add(outLabel);
		displayPanel.add(outText);
		
		add.addActionListener(ac);

		add(displayPanel);
		add(add, BorderLayout.SOUTH);
	}

	public void getData() {
		mmovieQueries = new MoviesQueries();
		mResults = mmovieQueries.getAllMovies();
		
		locQueries = new LocationQueries();
		locResults = locQueries.getAllLocations();
	}
}
